<template>
  <div>
  <el-container>
    <!-- 头部导航栏 -->
    <el-header>
      <el-menu :default-active="this.$route.path"
               class="el-menu-demo"
               mode="horizontal"
               @select="handleSelect"
               router
               text-color="#8590A6"
               id="header">
        <el-menu-item style="font-weight: 800;color: #0066FF;font-size: 33px;margin-left: 8%;font-family: DottedSongtiDiamondRegular">肆记</el-menu-item>
        <el-menu-item index="/index" style="margin-left: 20px">首页</el-menu-item>
        <el-menu-item index="/question">等你来答</el-menu-item>
        <el-menu-item index="/article">写个文章</el-menu-item>
        <el-menu-item index="/about">个人空间</el-menu-item>
        <el-menu-item>
          <el-input style="margin-left: 30px" placeholder="请输入你要搜索的内容" id="search"><i slot="suffix" class="el-input__icon el-icon-search" @click="doSearch" id="searchIcon"></i></el-input>
          <el-button type="primary" round id="searchBtn"  @click="show()">提问</el-button>


        </el-menu-item>
        <el-badge :value="109" :max="99" class="item" style="margin-left: 15%;margin-bottom: 1%">
          <el-button  icon="el-icon-message-solid" type="text" ></el-button>
        </el-badge>
        <el-badge :value="109" :max="99" class="item" style="margin-left: 3%;margin-bottom: 1%">
          <el-button  icon="el-icon-chat-dot-round" type="text" ></el-button>
        </el-badge>

<!--        <el-avatar shape="square" :size="42" style="margin-left: 5%" src="static/head.jpg" ></el-avatar>-->

        <el-dropdown style="margin-left: 5%" placement="bottom">
          <el-avatar shape="square" :size="42"  :src="imgUrl" ></el-avatar>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item><span @click="toMyHome()"><i class="el-icon-user"/>我的主页</span></el-dropdown-item>
            <el-dropdown-item><span @click="manage()"><i class="el-icon-setting"/>管理页面</span></el-dropdown-item>
            <el-dropdown-item><span @click="logOut()"><i class="el-icon-switch-button"/>退出登录</span></el-dropdown-item>
<!--            <el-dropdown-item>螺蛳粉</el-dropdown-item>-->
<!--            <el-dropdown-item disabled>双皮奶</el-dropdown-item>-->
<!--            <el-dropdown-item divided>蚵仔煎</el-dropdown-item>-->
          </el-dropdown-menu>
        </el-dropdown>
      </el-menu>
    </el-header>



    <el-main>
      <el-row>
        <el-col :span="24" >
          <router-view/>
        </el-col>
      </el-row>

    </el-main>
  </el-container>

  <question-dialog ref="question" ></question-dialog>
  </div>
</template>

<script>
  import QuestionDialog from "./question/QuestionDialog";
  import AboutMe from "./about/AboutMe";
  export default {
    name: 'App',
    components: {AboutMe, QuestionDialog},
    data() {
      return {
        dialogVisible: false,
        question: '',
        imgUrl:''
      };
    },
    created() {
      this.getHeadPic();
    },
    watch:{
      $route(to,from){
        console.log(from.path);//从哪来
        console.log(to.path);//到哪去
      }
    },
    methods: {
      getHeadPic()
      {
        this.$http.get("http://localhost:8989/fornote/user/getCurrent").then(response =>{
          this.imgUrl=response.data.data.headpic;
        })
      },
      handleSelect(key, keyPath) {
        console.log(key, keyPath);
      },
      doSearch() {
        alert("搜索触发")
      },
      show()
      {
        this.$refs.question.init();
      },
      logOut()
      {
        this.$confirm('退出登录？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          this.$http.get("http://localhost:8989/fornote/user/logOut").then(response =>{
            console.log(response.data);
            if(response.data.code==200)
            {
              this.$message({
                message:response.data.data,
                type:'success'
              })
              //清除登录信息
              sessionStorage.removeItem("user")
              this.$router.push("/login")
            }else if(response.data.code!=200)
            {
              this.$message({
                message:"登出失败！",
                type:"error"
              })
            }
          })
        })
      },
      toMyHome()
      {
        if(this.$route.path=='/about')
        {
          this.$message({
            message:"您已在个人主页了喔！",
            type:'warning'
          })
          return
        }
        this.$router.push("/about")
      },
      manage()
      {
        if(this.$route.path=='/manage')
        {
          this.$message({
            message:"您已在管理页面了喔！",
            type:'warning'
          })
          return
        }
        this.$router.push("/manage")
      },
    }
  }
</script>

<style>
  #header{
    font-weight: 600;
  }
  #search{
    border-radius: 20em;
    font-weight: 600;
  }
  #searchIcon:hover{
    color: #0066FF;
  }
  #searchBtn{
    font-weight: 600;
    margin-left: 39px;
  }
</style>
